﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CSharpCity.Tools.RandomNumberGenerators;

namespace EvoAlgLib
{
    public class VarFunc : Func
    {
        private String _var;
        private double _val;

        public VarFunc(String var): base(0)
        {
            this._var = var;
        }

        override public void setVars(Dictionary<String, Double> vars) {
            if (vars.Keys.Contains(this._var))
                this._val = vars[this._var];
        }

        public override double getVal(params double[] args)
        {
            return this._val;
        }

        public override void mutateVal(double pm)
        {
            double p = LibStatics.getRandomizer().NextDouble();
            if (p < pm)
                this._val += LibStatics.getRandomizer().Next(-1, 1);
        }

        public override string ToString()
        {
            return this._var;
        }
    }
}
